package Servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import bean.HttpGetRequest;
import bean.HttpRequest;
/**
 * Servlet implementation class getSenor
 */
public class getSenor extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		String ss;
		try {
			ss = HttpGetRequest.doGet();
			JSONArray jsonArray = JSONArray.fromObject(ss);
			JSONObject obj = jsonArray.getJSONObject(1);
			JSONArray senorArray = obj.getJSONArray("sensors");
			for(int i=0;i<senorArray.size();i++){
				JSONObject senorObj = senorArray.getJSONObject(i);
				request.setAttribute(senorObj.getString("idName"),senorObj.getInt("value"));
			}
			request.setAttribute("hospitalEntitys", "true");
			RequestDispatcher dispatcher = request.getRequestDispatcher("./pages/moritor.jsp");
			dispatcher .forward(request, response);
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request,response);
	}

}
